import React, { Component } from 'react';
import { Tabs } from 'antd';
import ShareLink from './sharelink';
import SendFile from './sendfile';
import ReceivedFile from './receivedfile';
import WaitFile from './waitfile';
import './index.less';

const { TabPane } = Tabs;

class Share extends Component {
	
	state = {
		key: "1"
	}
	
	componentDidMount(){
		const tabkey = sessionStorage.getItem("tabkey");
		if(tabkey){
			this.setState({key:tabkey});
		}
	}
	
	tabChange = key => {
		this.setState({key});
		sessionStorage.setItem("tabkey", key);
		if(key === "3"){
			if(this.child){
				this.child.refreshList();//父组件调用子组件的方法，刷新子组件
			}
		}
	}
	
	//父组件调用子组件的方法
	onRef = ref => {
		this.child = ref;
	}
	
	render(){
		return (
			<div className="tabs-page">
				<Tabs onChange={this.tabChange} type="card" activeKey={this.state.key}>
					<TabPane tab="我创建的分享链接" key="1">
						<ShareLink />
					</TabPane>
					<TabPane tab="已发起的分享" key="2">
						<SendFile />
					</TabPane>
					<TabPane tab="已接收的分享" key="3">
						<ReceivedFile onRef={this.onRef} />
					</TabPane>
					<TabPane tab="待接收的分享" key="4">
						<WaitFile />
					</TabPane>
				</Tabs>
			</div>
		)
	}
}

export default Share;